package com.drakulo.games.ais.core.delayed;

import java.math.BigDecimal;
import java.util.Map;

import com.drakulo.games.ais.core.Colony;
import com.drakulo.games.ais.core.Resource;
import com.drakulo.games.ais.core.building.Building;

/**
 * Represents a building action such as construction or upgrade
 */
public class BuildingAction extends MapAction {
	/** The source building */
	private Building building;
	/** True if it is an upgrade action */
	private boolean isUpgrade;

	/**
	 * Constructor for upgrade action
	 * 
	 * @param costMap
	 *            the cost map
	 * @param source
	 *            the source building to be upgraded
	 * @param duration
	 *            the action duration
	 * @param robotsUsed
	 *            the number of construction robots needed
	 */
	public BuildingAction(Colony c, Map<Resource, BigDecimal> costMap,
			Building building, int duration, int robotsUsed) {
		this(c, costMap, building, duration, robotsUsed, false);
	}

	public BuildingAction(Colony c, Map<Resource, BigDecimal> costMap,
			Building building, int duration, int robotsUsed, boolean isUpgrade) {
		super(c, costMap, duration, robotsUsed);
		this.building = building;
		this.isUpgrade = isUpgrade;
		// Update the upgrading flag in the building
		building.setUpgrading(isUpgrade);
	}

	/**
	 * @return the source building
	 */
	public Building getBuilding() {
		return this.building;
	}

	public boolean isUpgrade() {
		return this.isUpgrade;
	}

	@Override
	public String getGfxKey() {
		return this.building.getType().toString().toLowerCase();
	}

	public BuildingAction clone() {
		Building b = this.building.clone();
		return new BuildingAction(this.getColony(), this.getCostMap(), b, this.getDuration(),
				this.getRobotsUsed(), this.isUpgrade);
	}
}
